package com.niit.util;

/**
 * @Author: Chase
 * @Date: 2024/12/12
 */

/**
 * 数据转换工具类，防止数据转换异常，可以给默认值
 */
public class DataConvUtils {
    /**
     * String -> Double
     *
     * @param num        72㎡ or 13189元/㎡...
     * @param defaultNum
     * @return
     */
    public static double strToDouble(String num, double defaultNum) {
        try {
            return Double.parseDouble(num);
        } catch (NumberFormatException e) {
            return defaultNum;
        }
    }

    /**
     * String -> int
     *
     * @param num
     * @param defaultNum
     * @return
     */
    public static double strToInt(String num, int defaultNum) {
        try {
            return Integer.parseInt(num);
        } catch (NumberFormatException e) {
            return defaultNum;
        }
    }
}
